using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoldDigger.Models;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace GoldDigger.Sprites
{
    internal static class ItemSpriteFactory
    {
        public static ItemSprite Load(this ContentManager contentManager, Item item)
        {
            var gold = contentManager.GetGoldSpriteSheet();
            var pos = new Vector2(item.X, item.Y);
            switch (item.Type)
            {
                case ItemType.SmallGold:
                    return new SpriteSheetItemSprite(gold)
                               {
                                   Position = pos,
                                   Scale = 0.5f,
                                   Weight = 1f,
                                   Value = 200,
                                   MilliSecondsPerFrame = 150,
                                   SpriteAreaScale = 0.85f,
                               };
                case ItemType.MediumGold:
                    return new SpriteSheetItemSprite(gold)
                               {
                                   Position = pos,
                                   Scale = 0.8f,
                                   Weight = 1.5f,
                                   Value = 300,
                                   MilliSecondsPerFrame = 150,
                                   SpriteAreaScale = 0.85f,
                               };
                case ItemType.BigGold:
                    return new SpriteSheetItemSprite(gold)
                               {
                                   Position = pos,
                                   Scale = 1.3f,
                                   Weight = 3f,
                                   Value = 500,
                                   MilliSecondsPerFrame = 150,
                                   SpriteAreaScale = 0.85f,
                               };
                case ItemType.SmallRock:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/smallrock"))
                               {
                                   Position = pos,
                                   Scale = 0.7f,
                                   Weight = 3f,
                                   Value = 10,
                                   SpriteAreaScale = 0.85f
                               };
                case ItemType.BigRock:
                    return new SpriteSheetItemSprite(GetBigRockSpriteSheet(contentManager))
                               {
                                   Position = pos,
                                   Scale = 0.35f,
                                   Weight = 5f,
                                   Value = 20,
                                   MilliSecondsPerFrame = 300,
                                   SpriteAreaScale = 0.85f
                               };
                case ItemType.Diamond:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/diamond"))
                               {
                                   Position = pos,
                                   Scale = 0.3f,
                                   Weight = 1f,
                                   Value = 1000,
                                   SpriteAreaScale = 0.8f,
                               };
                case ItemType.Bucket:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/bucket"))
                               {
                                   Position = pos,
                                   Scale = 0.4f,
                                   Weight = 1.2f,
                                   Value = 10,
                                   SpriteAreaScale = 0.95f,

                               };
                case ItemType.Bird:
                    return new BirdSprite(GetBirdSpriteSheet(contentManager), 10f)
                               {
                                   Position = pos,
                                   Scale = 0.2f,
                                   Weight = 1f,
                                   Value = 20,
                                   MilliSecondsPerFrame = 150,
                                   SpriteAreaScale = 0.85f
                               };
                case ItemType.DiamondBird:
                    return new BirdSprite(GetDiamondBirdSpriteSheet(contentManager), 12f)
                               {
                                   Position = pos,
                                   Scale = 0.2f,
                                   Weight = 1f,
                                   Value = 1000,
                                   MilliSecondsPerFrame = 150,
                                   SpriteAreaScale = 0.85f
                               };
                case ItemType.Bomb:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/bomb"))
                               {
                                   Position = pos,
                                   Scale = 0.6f,
                                   Weight = 1.1f,
                                   Value = 0,
                                   SpriteAreaScale = 0.8f,
                               };
                case ItemType.Bag:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/bag"))
                               {
                                   Position = pos,
                                   Scale = 0.3f,
                                   Weight = 1f,
                                   Value = 0,
                                   SpriteAreaScale = 0.85f,
                               };
                case ItemType.Chest:
                    return new ItemSprite(contentManager.Load<Texture2D>(@"Images/chest"))
                               {
                                   Position = pos,
                                   Scale = 0.35f,
                                   Weight = 3f,
                                   Value = 0,
                                   SpriteAreaScale = 0.88f,
                               };

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        private static SpriteSheetItemInfo _gold;
        private static SpriteSheetItemInfo GetGoldSpriteSheet(this ContentManager contentManager)
        {
            if (_gold != null) return _gold;

            var image = contentManager.Load<Texture2D>(@"Images/coin-sheet");
            Rectangle frameSize = new Rectangle(0, 0, 42, 46);
            Point sheetSize = new Point(3, 2);
            return _gold = new SpriteSheetItemInfo
            {
                FrameSize = frameSize,
                SheetSize = sheetSize,
                Image = image,
                RandomOrder = true,
            };
        }

        private static SpriteSheetItemInfo _bigRock;
        private static SpriteSheetItemInfo GetBigRockSpriteSheet(this ContentManager contentManager)
        {
            if (_bigRock != null) return _bigRock;

            var image = contentManager.Load<Texture2D>(@"Images/bigrock");
            Rectangle frameSize = new Rectangle(0, 0, 172, 190);
            Point sheetSize = new Point(2, 1);
            return _bigRock = new SpriteSheetItemInfo
            {
                FrameSize = frameSize,
                SheetSize = sheetSize,
                Image = image,
                //RandomOrder = true,
            };
        }

        private static SpriteSheetItemInfo _bird;
        private static SpriteSheetItemInfo GetBirdSpriteSheet(this ContentManager contentManager)
        {
            if (_bird != null) return _bird;

            var image = contentManager.Load<Texture2D>(@"Images/bird");
            Rectangle frameSize = new Rectangle(0, 0, 210, 125);
            Point sheetSize = new Point(2, 2);
            return _bird = new SpriteSheetItemInfo
            {
                FrameSize = frameSize,
                SheetSize = sheetSize,
                Image = image,
                RandomOrder = true,
            };
        }

        private static SpriteSheetItemInfo _diamondBird;
        private static SpriteSheetItemInfo GetDiamondBirdSpriteSheet(this ContentManager contentManager)
        {
            if (_diamondBird != null) return _diamondBird;

            var image = contentManager.Load<Texture2D>(@"Images/diamondbird");
            Rectangle frameSize = new Rectangle(0, 0, 250, 120);
            Point sheetSize = new Point(2, 2);
            return _diamondBird = new SpriteSheetItemInfo
            {
                FrameSize = frameSize,
                SheetSize = sheetSize,
                Image = image,
                RandomOrder = true,
            };
        }
    }
}
